unit ViewFormUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, Grids, DBGrids, ComCtrls, StdCtrls, Buttons, OleCtnrs,
  IBFilterDialog;

type
  TViewForm = class(TForm)
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    DataSource3: TDataSource;
    DBGrid3: TDBGrid;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    DBGrid4: TDBGrid;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    TabSheet3: TTabSheet;
    BitBtn2: TBitBtn;
    OleContainer: TOleContainer;
    BitBtn3: TBitBtn;
    IBFilterDialog1: TIBFilterDialog;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    procedure SaveCurrFile(path:string);
  end;

var
  ViewForm: TViewForm;

implementation

uses DataUnit, IBQuery;

{$R *.dfm}

procedure TViewForm.BitBtn1Click(Sender: TObject);
begin
    with DataSource3.DataSet as TIBQuery do begin
        Close;
        ParamByName('fileid').AsInteger:= DataSource2.DataSet.FieldByName('id_file').AsInteger;
        Open;
    end;

end;

procedure TViewForm.BitBtn2Click(Sender: TObject);
var
  BlSt: TStream;
  FileStream: TFileStream;
  pp: string;
begin
    pp:=ExtractFilePath(Application.ExeName)+'tmp.xls';
    SaveCurrFile(pp);
    OleContainer.DestroyObject;
    try
        OleContainer.CreateObjectFromFile(pp,false);
    except
    end;
end;

procedure TViewForm.BitBtn3Click(Sender: TObject);
begin
    OleContainer.Close;
end;

procedure TViewForm.BitBtn4Click(Sender: TObject);
begin
    IBFilterDialog1.Execute;
    IBFilterDialog1.ReBuildSQL;
    ShowMessage(IBFilterDialog1.ModifiedSQL.Text);
end;

procedure TViewForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    Action:=caFree;
end;

procedure TViewForm.FormCreate(Sender: TObject);
begin
    DataSource1.DataSet.Open;
    DataSource2.DataSet.Open;
end;

procedure TViewForm.SaveCurrFile(path:string);
begin
    MainData.SaveBlobFile(DataSource2.DataSet,'inFile',path);
end;

end.
